import {
    getmain,
    getmyattendancerecord,
    getmyattendancedetail
} from '@/services/attendance/attendance';

export default {
    namespace: 'attendanceMineList',
    state: {
        data: [],
        pagination: {
            pageSize: 10,
            current: 1,
            total: 0
        }
    },
    effects: {
        *getData({ payload }, { call, put }) {
            const response = yield call(getmain, payload);
            if (response.code === 10000) {
                if (response.data) {
                    yield put({
                        type: 'save',
                        payload: {
                            main: response.data
                        }
                    });
                }
            }
        },

        *getmyattendancerecord({ payload }, { call, put }) {
            const response = yield call(getmyattendancerecord, payload.parame);
            if (response.code === 10000) {
                yield put({
                    type: 'save',
                    payload: {
                        attendancerecord: response.data.rows,
                        pagination: {
                            pageSize: response.data.pageSize,
                            current: response.data.pageNo,
                            total: response.data.total
                        }
                    }
                });
            }
        },

        *getmyattendancedetail({ payload }, { call, put }) {
            const response = yield call(getmyattendancedetail, payload.parame);
            if (response.code === 10000) {
                yield put({
                    type: 'save',
                    payload: {
                        attendancedetail: response.data.rows
                    }
                });
            } else {
                // 当假如其他状态，全部把modal数据清空
                yield put({
                    type: 'save',
                    payload: {
                        attendancedetail: []
                    }
                });
            }
        }
    },
    reducers: {
        save(state, { payload }) {
            return {
                ...state,
                ...payload
            };
        },
        setPagination(state, { pagination }) {
            return {
                ...state,
                pagination
            };
        }
    }
};
